package com.hackerrank.challenges.connectingtowns;

import java.util.Scanner;

public class Solution {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		for(int t = 0; t < T; t++) {
			int n = in.nextInt(), w = 1;
			for(int i = 1; i < n; i++)
				w = (w * in.nextInt()) % 1234567;
			System.out.println(w);
		}
	}
}
